package com.gl.saasservice.house.repository;

import com.gl.saasservice.house.entity.House;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

public interface HouseRepository extends PagingAndSortingRepository<House, String>, JpaSpecificationExecutor<House> {

    List<House> findByIdIn(List<String> houseIds);

    @Query("from House where residenceCommunityId=?1 and buildingNum=?2 and unit=?3 and contractNumber is  not  null ")
    List<House> findByResidenceCommunityIdAndBuildingNumAndUnit(String residenceCommunityId, Long buildingNum, Long unit);

    @Override
    void deleteById(String s);

    @Modifying
    @Query(value = "UPDATE saas_house h SET h.match_status = ?4 WHERE h.residence_community_id = ?1 AND h.org_id = ?2 AND h.match_status = ?3 AND h.audit_status = 1", nativeQuery = true)
    int updateMatchStatus(String residenceCommunityId, Long orgId, Integer matchStatus, Integer status);

    List<House> findByOrgIdIn(List<Long> orgIds);

    List<House> findByOrgId(Long orgId);

    List<House> findByPaymentStatusAndIdIn(Integer paymentStatus, List<String> houseIds);

    @Modifying
    @Query(value = "UPDATE saas_house h SET h.pwd_lock_status = ?2 WHERE h.id = ?1", nativeQuery = true)
    int updateLockStatusById(String houseId, Integer status);

    int countByResidenceCommunityId(String residenceCommunityId);

    List<House> findByResidenceCommunityId(String residenceCommunityId);
    List<House> findByResidenceCommunityIdAndStatus(String residenceCommunityId ,Integer status);

    List<House> findByResidenceCommunityIdAndBuildingNumAndUnitAndHouseNatureIn(String residenceCommunityId, Long buildingNum, Long unit, List<Integer> houseNature);

}
